<template>
  <gj-loadmore :bottom-method="loadBottom" ref="loadmore">
    <table class="table">
      <tbody class="rockmans">
        <tr v-for="(item,index) in rockmans.list" :key="index">
          <td class="one" @click.stop.prevent="toDetail(item)">
            <img :src="item.userHead" />
            <div class="inline-block">
              <div class="nickname">{{item.nickname}}</div>
              <div class="date-time">{{item.subTime}}</div>
            </div>
          </td>
          <td class="two">订阅了我</td>
          <td class="three">订阅中</td>
        </tr>
      </tbody>
    </table>
  </gj-loadmore>
</template>

<script>
  import CommonUtil from 'common/common.util'
  import LocalDAO from 'common/localDAO'
  import RemoteDAO from 'common/remoteDAO'
  import Constant from 'common/constant'
  import LoadMore from 'components/LoadMore'
  export default {
    data () {
      return {
        userCode: LocalDAO.getUserCode(),
        pageSize: 20,
        pageNo: 1,
        rockmans: {
          list: []
        }
      }
    },
    components: {
      'gj-loadmore': LoadMore
    },
    methods: {
      //上拉加载
      loadBottom () {
        this.getData();
      },

      //获取订阅我的粉丝列表
      getData () {
        RemoteDAO.callUC12008309(this.userCode, this.pageSize, this.pageNo, "3", "1", "1", "", "", "1", response => {
          if (response.error == "0") {
            if(response.data.body.length > 0){
              let list = [];
              response.data.body.forEach((item,index,array) => {
                let object = {};
                Object.assign(object,{
                  userCode: item.USER_CODE,
                  nickname: item.NICKNAME,
                  userHead: item.USER_HEAD == "" ? CommonUtil.getDefaultUserHead(item.USER_CODE) : item.USER_HEAD,
                  subTime: CommonUtil.formatDate(item.COMMUNITY_DATE) + " " + CommonUtil.formatHourMinute(item.COMMUNITY_TIME)
                });
                list.push(object)
              })
              this.rockmans.list = this.rockmans.list.concat(list);
              //更新分享页数据
              var shareFans = LocalDAO.getShareFans();
              if(shareFans == null){
                shareFans = {};
                shareFans.rockmans = {};
                shareFans.rockmans.list = [];
              }else if(typeof(shareFans.rockmans.list) == "undefined"){
                shareFans.rockmans.list = [];
              }
              shareFans.rockmans.list = this.rockmans.list;
              LocalDAO.setShareFans(shareFans);
              //上拉加载下拉刷新
              if (list.length == this.pageSize) {
                this.pageNo = this.pageNo + 1;
                this.$refs.loadmore.onBottomLoaded();//加载成功
              }else{
                this.$refs.loadmore.onBottomAllLoaded();//无更多数据
              }
            }else{
              if(this.pageNo == 1){
                this.$refs.loadmore.onBottomError("暂无数据");//暂无数据
              }else{
                this.$refs.loadmore.onBottomAllLoaded();//无更多数据
              }
            }
          }else{
            this.$refs.loadmore.onBottomError(response.data);//加载失败
          }
        })
      },

      //点击牛人头像跳转至牛人详情页面
      toDetail (item) {
        this.$router.push({path:'/otherdetail',query:{userCode:item.userCode}})
      }
    }
  }
</script>
